package com.example.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by Hy on 2018/8/7.
 * 并发测试
 */
public class CountDownLatchtest1 implements Runnable{
    final AtomicInteger number = new AtomicInteger();
    volatile boolean bol = false;

    @Override
    public void run() {
        System.out.println("number.getAndIncrement():"+number.getAndIncrement());
        synchronized (this){
            try {
              if(!bol){
                  System.out.println("bol的值："+bol);
                  bol = true;
                  Thread.sleep(1000);
              }
            }catch (Exception e){
                e.printStackTrace();
            }
            System.out.println("并发数量为"+number.intValue());
        }
    }

    public static void main(String[] args) {
        ExecutorService pool = Executors.newCachedThreadPool();
        CountDownLatchtest1 test = new CountDownLatchtest1();
        for (int i =0;i<10;i++){
            pool.execute(test);
        }
    }
}
